package com.xuesinuo.ots.config.auth;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;

import com.xuesinuo.ots.tool.UserTool;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Configuration
@Aspect
public class AuthAspect {
    private final UserTool authTool4User;

    @Around("@annotation(authAnn)")
    public Object around(ProceedingJoinPoint joinPoint, Auth authAnn) throws Throwable {
        String auth = authAnn.value();
        if (auth.trim().equals("")) {
            authTool4User.checkLogin();
        } else {
            authTool4User.checkAuth(auth);
        }
        return joinPoint.proceed();
    }
}
